package cn.jwelll.bxcstock.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import cn.jwelll.bxcstock.MainActivity;
import cn.jwelll.bxcstock.common.ConstValue;
import cn.jwelll.bxcstock.ui.login.LoginActivity;

public class ActivityUtil {
    /**
     * 启动Intent跳转界面，且要返回
     *
     * @param activity      当前界面
     * @param activityClass 目标界面Class
     * @param bundle        参数
     * @param requestCode   请求码
     */
    public static void startActivityForResult(@NonNull Activity activity, @NonNull Class activityClass,
                                              Bundle bundle, int requestCode) {
        Intent intent = new Intent(activity, activityClass);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        activity.startActivityForResult(intent, requestCode);
    }

    /**
     * 登录界面
     *
     * @param toMain 是否去home界面
     */
    public static void startLogin(Context activity) {
        Intent intent = new Intent(activity, LoginActivity.class);
        if (!(activity instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        activity.startActivity(intent);
    }


    /***
     * 跳转到Activity
     * @param context
     * @param cls
     */
    public static void startActivity(Context context, Class<?> cls) {
        Intent intent = new Intent(context, cls);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }

    public static void startMainActivity(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }


        context.startActivity(intent);
    }

    /**
     * 跳转主页，清理栈顶的其他activity
     */
    public static void startMainActivityClearTop(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        if (context instanceof Activity) {
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }


        context.startActivity(intent);
    }

}
